package anthology.daily_question._24_10;
//https://leetcode.cn/problems/maximum-swap/description/
public class _0670最大交换 {
    class Solution {
        public int maximumSwap(int num) {
            char[] charArray = String.valueOf(num).toCharArray();
            int n = charArray.length;
            int maxNum = num;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    swap(charArray, i, j);
                    maxNum = Math.max(maxNum, Integer.parseInt(new String(charArray)));
                    swap(charArray, i, j);
                }
            }
            return maxNum;
        }

        public void swap(char[] charArray, int i, int j) {
            char temp = charArray[i];
            charArray[i] = charArray[j];
            charArray[j] = temp;
        }
    }
}
